package com.dk.controller;

import com.dk.pojo.TAuthor;
import com.dk.service.TAuthorServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tAuthorController")
public class TAuthorController {

    //作者
    @Autowired
    private TAuthorServiceI tAuthorServiceI;

    //跳转作者查询页
    @RequestMapping("list")
    public String listGet(){
        return "tAuthor/list";
    }

    //查询作者
    @RequestMapping("getInfoServer")
    @ResponseBody
    public List<TAuthor> getInfoServer(){
        List<TAuthor> list = tAuthorServiceI.getInfoServer();
        return list;
    }

    //跳转作者增加页面
    @RequestMapping("insertInfo")
    public String insertInfo(){
        return "tAuthor/add";
    }

    //确认增加作者
    @RequestMapping("saveById")
    @ResponseBody
    public int saveById(TAuthor tAuthor){
        tAuthorServiceI.saveById(tAuthor);
        return 1;
    }

    //回显作者
    @RequestMapping("updateInfo/{authorId}")
    public String getUpdateInfo(@PathVariable("authorId")Integer authorId, Model model){
        TAuthor tAuthor = tAuthorServiceI.getUpdateInfo(authorId);
        model.addAttribute("tAuthor",tAuthor);
        return "tAuthor/update";
    }

    //确定修改作者
    @RequestMapping("updateById")
    @ResponseBody
    public int updateById(TAuthor tAuthor){
        tAuthorServiceI.updateById(tAuthor);
        return 1;
    }

    //删除作者
    @RequestMapping("deleteById/{authorId}")
    @ResponseBody
    public int deleteById(@PathVariable("authorId")Integer authorId){
        tAuthorServiceI.deleteById(authorId);
        return 1;
    }
}
